import type { AxiosResponsePage, AxiosResponseType } from '@/types/http'
import { requestAPI } from '@/utils/http/request'
/**
 * 获取首页所有卫星轨道数据
 * @returns
 */
export const getHomeSatellite = (
  pageNum: number,
  pageSize: number,
  country: string,
  orbit_type: number,
  orbit_status: number,
  payload_status: number,
  sat_type: string
) => {
  let url = `/api/satellite/home/page?pageNum=${pageNum}&pageSize=${pageSize}`
  if (country && country !== '全部') {
    url += `&country=${country}`
  }
  if (orbit_type !== -1) {
    url += `&orbit_type=${orbit_type}`
  }
  if (orbit_status !== -1) {
    url += `&orbit_status=${orbit_status}`
  }
  if (payload_status !== -1) {
    url += `&payload_status=${payload_status}`
  }
  if (sat_type && sat_type !== '全部') {
    url += `&sat_type=${sat_type}`
  }
  return requestAPI.get<AxiosResponsePage<SatelliteInfo[]>>(url)
}

/**
 * 获取首页所有卫星列表数据
 * @returns
 */
export const getSatelliteList = (
  pageNum: number,
  pageSize: number,
  country: string,
  orbit_type: number,
  orbit_status: number,
  payload_status: number,
  sat_type: string,
  taskId: number
) => {
  let url = `/api/satellite/list/page?pageNum=${pageNum}&pageSize=${pageSize}`
  if (country && country !== '全部') {
    url += `&country=${country}`
  }
  if (orbit_type !== -1) {
    url += `&orbit_type=${orbit_type}`
  }
  if (orbit_status !== -1) {
    url += `&orbit_status=${orbit_status}`
  }
  if (payload_status !== -1) {
    url += `&payload_status=${payload_status}`
  }
  if (sat_type && sat_type !== '全部') {
    url += `&sat_type=${sat_type}`
  }
  if (taskId !== -1) {
    url += `&taskId=${taskId}`
  }
  return requestAPI.get<AxiosResponsePage<Satellite[]>>(url)
}
/**
 * 获取卫星详情数据
 * @returns
 */
export const getSatelliteDetail = (data: { norad: number }) => {
  const url = `/api/satellite/satellite/param`
  return requestAPI.post<AxiosResponseType<SatelliteDetail>>(url, data)
}

/**
 * 获取重点关注卫星
 * @returns
 */
export const getImportantSatelliteList = (pageNum: number, pageSize: number, taskId: number | null) => {
  let url = `/api/satellite/list/main/page?pageNum=${pageNum}&pageSize=${pageSize}`
  if (taskId) {
    url += `&taskId=${taskId}`
  }
  return requestAPI.get<AxiosResponsePage<SatelliteDetail[]>>(url)
}
/**
 * 新增战场
 * @param battle
 */
export const saveBattle = (battle: BattleForm) => {
  const url = `/api/battle/save`
  return requestAPI.post<AxiosResponseType<any>>(url, battle)
}
/**
 * 更新战场
 * @param battle
 */
export const updateBattle = (battle: BattleForm) => {
  const url = `/api/battle/update`
  return requestAPI.put<AxiosResponseType<any>>(url, battle)
}
/**
 * 删除战场
 * @param battle
 */
export const deleteBattle = (battleId: number) => {
  const url = `/api/battle/del/${battleId}`
  return requestAPI.delete<AxiosResponseType<any>>(url)
}
/**
 * 新增任务
 * @param battle
 */
export const saveTask = (task: TaskForm) => {
  const url = `/api/battle/saveTask`
  return requestAPI.post<AxiosResponseType<any>>(url, task)
}
/**
 * 更新任务
 * @param battle
 */
export const updateTask = (task: TaskForm) => {
  const url = `/api/battle/updateTask`
  return requestAPI.put<AxiosResponseType<any>>(url, task)
}
/**
 * 删除任务
 * @param battle
 */
export const deleteTask = (taskId: number) => {
  const url = `/api/battle/delTask/${taskId}`
  return requestAPI.delete<AxiosResponseType<any>>(url)
}
/**
 * 战场列表
 * @param battle
 */
export const getBattleList = () => {
  const url = `/api/battle/list`
  return requestAPI.get<AxiosResponseType<BattleForm[]>>(url)
}
/**
 * 任务列表
 * @param battle
 */
export const getTaskList = (battleId: number) => {
  const url = `/api/battle/taskList?battleId=${battleId}`
  return requestAPI.get<AxiosResponseType<TaskForm[]>>(url)
}
/**
 * 根据任务Id获取TLE数据
 * @returns
 */
export const getTLEDataByTaskId = (taskId: number) => {
  const url = `/api/battle/tleByTaskId?taskId=${taskId}`
  return requestAPI.get<AxiosResponseType<TLEDataResponse>>(url)
}
/**
 * 获取卫星统计数据
 * @returns
 */
export const getSatelliteCount = () => {
  const url = `/api/battle/count`
  return requestAPI.get<AxiosResponseType<{ count: number }>>(url)
}
/**
 * 获取卫星TLE数据
 * @param data
 * @returns
 */
export const getSatelliteTLEData = (data: { norads: string[] }) => {
  const url = `/api/satellite/satellite/tle`
  return requestAPI.post<AxiosResponseType<{ noradId: number; satelliteTleResp: SatelliteTle }[]>>(url, data)
}
/**
 * 获取任务相关的卫星之间的关系
 * @param taskId
 * @returns
 */
export const getSatelliteRelations = (taskId: number, type: string) => {
  const url = `/api/battle/netView?taskId=${taskId}&relationType=${type}`
  return requestAPI.get<AxiosResponseType<{ nodes: SatelliteNode[]; relationships: SatelliteRelation[] }>>(url)
}

/**
 * 获取卫星关系下拉框
 * @returns
 */
export const getSatelliteRelationTypes = () => {
  const url = `/api/battle/netViewSelect`
  return requestAPI.get<AxiosResponseType<string[]>>(url)
}

/**
 * 威胁卫星数量统计
 * @param taskId
 * @returns
 */
export const threatStatisticsCount = (taskId: number) => {
  const url = `/api/battle/threatStatistics?taskId=${taskId}`
  return requestAPI.get<
    AxiosResponseType<{
      days: number
      unitCount: number
      highThreatCount: number
      avgScore: number
    }>
  >(url)
}
/**
 * 卫星威胁等级分布
 * @param taskId
 * @returns
 */
export const threatLevelAnalysis = (taskId: number, noradId?: number, country?: string) => {
  let url = `/api/battle/threatLevel?taskId=${taskId}`
  if (noradId) {
    url += `&noradId=${noradId}`
  }
  if (country) {
    url += `&country=${country}`
  }
  return requestAPI.get<AxiosResponseType<Record<string, number>>>(url)
}
/**
 * 高威胁卫星数量变化
 * @param taskId
 * @returns
 */
export const highThreatAnalysis = (taskId: number, noradId?: number, country?: string) => {
  let url = `/api/battle/highThreat?taskId=${taskId}`
  if (noradId) {
    url += `&noradId=${noradId}`
  }
  if (country) {
    url += `&country=${country}`
  }
  return requestAPI.get<AxiosResponseType<{ date: string; count: number }[]>>(url)
}
/**
 * 卫星平均威胁趋势
 * @param taskId
 * @returns
 */
export const avgThreatAnalysis = (taskId: number, noradId?: number, country?: string) => {
  let url = `/api/battle/avgThreat?taskId=${taskId}`
  if (noradId) {
    url += `&noradId=${noradId}`
  }
  if (country) {
    url += `&country=${country}`
  }
  return requestAPI.get<AxiosResponseType<{ date: string; avgThreatScore: number }[]>>(url)
}
/**
 * 卫星威胁波动性
 * @param taskId
 * @returns
 */
export const variationThreatAnalysis = (taskId: number, country?: string) => {
  let url = `/api/battle/variationThreat?taskId=${taskId}`
  if (country) {
    url += `&country=${country}`
  }
  return requestAPI.get<AxiosResponseType<{ date: string; variation: number }[]>>(url)
}
/**
 * 计算威胁度
 * @param taskId
 * @param beginDate
 * @param endData
 * @returns
 */
export const calThreatAnalysis = (taskId: number, beginDate: string, endData: string) => {
  const url = `/api/battle/calThreat?taskId=${taskId}&beginDate=${beginDate}&endDate=${endData}`
  return requestAPI.get<AxiosResponseType<any>>(url)
}
/**
 * 建议
 * @param taskId
 * @returns
 */
export const getSuggestionOfTask = (taskId: number) => {
  const url = `/api/battle/threatSuggestion?taskId=${taskId}`
  return requestAPI.get<AxiosResponseType<string>>(url)
}
/**
 * 可打击度分析
 * @param taskId
 * @returns
 */
export const gettargetStrike = (taskId: number) => {
  const url = `/api/battle/targetStrike?taskId=${taskId}`
  return requestAPI.get<AxiosResponseType<{ strikeDegree: number; threatDegree: number; days: number }>>(url)
}
/**
 * 保存配置
 * @param data
 * @returns
 */
export const saveSceneConfig = (data: SceneConfig) => {
  const url = `/api/battle/saveSceneConfig`
  return requestAPI.post<AxiosResponseType<unknown>>(url, data)
}
/**
 * 获取配置
 * @param taskId
 * @returns
 */
export const getSceneConfig = (taskId: number) => {
  const url = `/api/battle/sceneConfigById?taskId=${taskId}`
  return requestAPI.get<AxiosResponseType<SceneConfig>>(url)
}
/**
 * 获取武器列表
 * @returns
 */
export const getWeapons = () => {
  const url = `/api/battle/weaponList`
  return requestAPI.get<AxiosResponseType<Weapon[]>>(url)
}
/**
 * 卫星可打击度列表
 * @param taskId
 * @param pageNum
 * @param pageSize
 * @returns
 */
export const getStrikeSatellites = (taskId: number, pageNum: number, pageSize: number) => {
  const url = `/api/battle/strikeList?taskId=${taskId}&pageNum=${pageNum}&pageSize=${pageSize}`
  return requestAPI.get<AxiosResponsePage<SatelliteStrike[]>>(url)
}
/**
 * 卫星威胁度列表
 * @param taskId
 * @param pageNum
 * @param pageSize
 * @param noradId
 * @param country
 * @returns
 */
export const getSatelliteThreatList = (
  taskId: number,
  pageNum: number,
  pageSize: number,
  noradId?: number,
  country?: string
) => {
  let url = `/api/battle/threatList?taskId=${taskId}&pageNum=${pageNum}&pageSize=${pageSize}`
  if (noradId) {
    url += `&noradId=${noradId}`
  }
  if (country) {
    url += `&country=${country}`
  }
  return requestAPI.get<AxiosResponsePage<SatelliteThreat[]>>(url)
}
